home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VGA_VUL1.ZIP / BOARDZ.ASM next >
Assembly Source File  |  1995-06-17  |  16KB  |  378 lines

  1. ;==============================================================================;
  2. ;                                                                              ;
  3. ;       Assembler program by Vulture.                                          ;
  4. ;       This program scrolls a text and displays a 3d-starfield.               ;
  5. ;       It's a BBS advertisement.                                              ;
  6. ;                                                                              ;
  7. ;       Current Date: 13-2-95         Vulture                                  ;
  8. ;                                                                              ;
  9. ;==============================================================================;
  10.  
  11. DOSSEG              ; Sort the segment using DOS standard CODE DATA STACK
  12. .MODEL SMALL        ; Code is smaller than 64kB (code & data)
  13. .STACK 200h         ; Specify stack
  14. .286                ; Allow 80286 instructions
  15. .CODE               ; Codesegment starts here
  16. JUMPS               ; Let Tasm handle out of range jumps
  17. ASSUME CS:@CODE     ; cs points to codesegment
  18.  
  19. ; === DATA ===   
  20.  
  21. INCLUDE Font.dat    ; File with font data
  22. INCLUDE Numbers.dat ; Include 500 random numbers between -200 and 200
  23.  
  24. Message  DB   13,10,"Code by Vulture.",13,10,"$"  ; Important message  :)
  25.  
  26. Star_Struc      STRUC   ; Format of star (like a record in Pascal)
  27.      X   DW   0         ; X-position of star
  28.      Y   DW   0         ; Y-position of star
  29.      Z   DW   0         ; Z-position of star
  30.      Old DW   0         ; Where to erase old star
  31.      Col DB   0         ; Color of star
  32. Star_Struc      ENDS
  33.  
  34. StarStrucSize = 9       ; Number of bytes per entry ( 4 wordz and a byte )
  35.  
  36. ScreenWidth   EQU 320   ; Obvious
  37. ScreenHeight  EQU 200   ; Obvious
  38. MaxStars      EQU 250   ; Maximum number of stars
  39. MaxNumbers    EQU 500   ; Number of random numbers defined  
  40. MaxZ          EQU 4096  ; StartZvalue for all stars
  41. MinZ          EQU 0     ; If Z = 0 then star is dead
  42.  
  43. XIndex        DW  250   ; Index to X-numbers
  44. YIndex        DW  125   ; Index to Y-numbers
  45. WarpSpeed     DW  20    ; Speed of stars  
  46. NumActive     DW  0     ; Number of stars active
  47.  
  48. Stars     Star_Struc MaxStars DUP (?)   ; Array of star-records
  49.  
  50. Palette DB 0,0,0        ; Palette info for first 5 colors (font)
  51.         DB 0,0,0
  52.         DB 52,0,0
  53.         DB 42,0,0
  54.         DB 32,0,0
  55.         DB  0,0,0                     ; Base color black => R,G,B
  56.     i=15                              ; 16 grey shades
  57.     REPT  16
  58.           DB  3*i,3*i,3*i
  59.        i=i-1
  60.     ENDM
  61.  
  62. PaletteArray  DB 768 DUP (?)          ; Array to hold the palette
  63.  
  64. Text    DB 'if u wanna experience some cewl boardz in the netherlands '
  65.         DB 'call firehouse 058-661590    detonator 05111-4307   or   '
  66.         DB 'mark of cain 058-672111      cu around. . . . . .'
  67.         DB '                            ',0           ; Text to scroll
  68.  
  69. Order   DB 'abcdefghijklmnopqrstuvwxyz0123456789-. '  ; Order of characters
  70.  
  71. ; === PROCEDURES ===
  72.  
  73. SetVGA PROC NEAR                ; Get into VGA mode
  74.     mov     ax,0013h            ; Set the videomode 320*200*256
  75.     int     10h                 ; Call VID interrupt
  76.     ret
  77. SetVGA ENDP
  78.  
  79. SetText PROC NEAR               ; Get into character mode
  80.     mov     ax,0003h            ; Set 80x25x16 char mode
  81.     int     10h                 ; Call VID interrupt
  82.     ret
  83. SetText ENDP
  84.  
  85. WaitVrt PROC NEAR               ; Waits for vertical retrace to reduce "snow"
  86.     mov     dx,3dah
  87. Vrt:
  88.     in      al,dx
  89.     test    al,8
  90.     jnz     VRT                 ; Wait until Verticle Retrace starts
  91. NoVrt:
  92.     in      al,dx
  93.     test    al,8
  94.     jz      NoVRT               ; Wait until Verticle Retrace ends
  95.     ret                         ; Return to main program
  96. WaitVrt ENDP
  97.  
  98. SavePalette PROC NEAR           ; Saves entire palette in array
  99.     cli                         ; Disable interrupts
  100.     mov     bp,offset PaletteArray  ; Point to start of array
  101.     mov     cx,768              ; Save all R,G,B registers
  102.     mov     dx,03c7h            ; Read register
  103.     mov     al,0                ; Start at 0
  104.     out     dx,al               ; Write to port
  105.     mov     dx,03c9h            ; Read data register
  106. Grab:
  107.     in      al,dx               ; Read value from port
  108.     and     al,3fh              ; Mask of upper 2 bits
  109.     mov     byte ptr [bp],al    ; Store the value in aray
  110.     inc     bp                  ; Point to the next one
  111.     loop    Grab                ; Loop until cx = 0
  112.     sti                         ; Enable interrupts
  113.     ret                         ; Return to main program
  114. SavePalette ENDP
  115.  
  116. FadeOut PROC NEAR               ; Fades screen to black
  117.     cli                         ; Disable interrupts
  118.     mov     bp,offset PaletteArray  ; Point to start of array
  119.     mov     cx,64               ; Repeat 64 times (0..63)
  120. OneCycle:
  121.     mov     bx,0                ; Set counter
  122. Decrease:
  123.     cmp     byte ptr [bp],0     ; Is it 0 already ?
  124.     je      Fading              ; Yep => Do the next
  125.     dec     byte ptr [bp]       ; Nope => Decrease by one
  126. Fading:
  127.     inc     bp                  ; Point to next value
  128.     inc     bx                  ; Increase counter
  129.     cmp     bx,768              ; Have we reached the end ?
  130.     jl      Decrease            ; No => Do another one
  131.     push    cx                  ; Save 1st loop counter
  132.     call    WaitVrt             ; Wait for retrace
  133.     sub     bp,768              ; Point to start
  134.     mov     bx,0                ; Reset counter
  135.     mov     cx,768              ; Do all colors
  136.     mov     dx,03c8h            ; Write register
  137.     mov     al,0                ; Start at 0
  138.     out     dx,al               ; Write to port
  139.     inc     dx                  ; Writing => 03c8h + 1 = 03c9h
  140. WriteAll:
  141.     mov     al,byte ptr [bp]    ; Store value in al
  142.     out     dx,al               ; Give it to the VGA
  143.     inc     bp                  ; Point to next one
  144.     inc     bx                  ; Increase counter
  145.     loop    WriteAll            ; Loop while cx > 0
  146.     pop     cx                  ; Restore 1st loop counter
  147.     sub     bp,768              ; Point to start
  148.     loop    OneCycle            ; Loop while cx > 0
  149.     sti                         ; Enable interrupts
  150.     ret                         ; Return to main program
  151. FadeOut ENDP
  152.  
  153. CalcStar PROC NEAR
  154.     pusha                               ; Put all registers on stack
  155.     mov     si,0                        ; si points to first star
  156. StartCalc:                              ; Start searching for empty slots
  157.     cmp     [NumActive],MaxStars        ; Check for room
  158.     jae     NoEmptySpace                ; No room => exit
  159.  
  160. SearchSlot:
  161.     cmp     word ptr [Stars.Z+si],MinZ  ; If Z = 0 then slot is empty
  162.     je      FillSlot
  163.  
  164.     add     si,StarStrucSize            ; si points to next star
  165.     cmp     si,StarStrucSize*MaxStars   ; Have we done entire array ?
  166.     jb      SearchSlot                  ; No => search again
  167.     jmp     NoEmptySpace                ; Yes => exit
  168.  
  169. FillSlot:
  170.     mov     di,[XIndex]                 ; Grab Xindex and put it in di
  171.     add     di,di                       ; Make WORD index
  172.     mov     ax,[Numbers+di]             ; Get the number
  173.     shl     ax,3                        ; Multiply by 8   
  174.     mov     [Stars.X+si],ax             ; Save the number
  175.  
  176.     mov     di,[YIndex]                 ; Do the same for Y
  177.     add     di,di
  178.     mov     ax,[Numbers+di]
  179.     shl     ax,3
  180.     mov     [Stars.Y+si],ax
  181.  
  182.     mov     [Stars.Z+si],MaxZ           ; Give star the Z offset
  183.     mov     al,0                        ; Also give it basecolor 0 (black)   
  184.     mov     [Stars.Col+si],al           ; Store the color
  185.  
  186.     inc     [NumActive]                 ; Increase star counter
  187.  
  188.     inc     [XIndex]                    ; Increase the X index
  189.     cmp     [XIndex],MaxNumbers         ; Have we reached the end of the list?
  190.     jb      XindNotMax                  ; No => continue
  191.     mov     [XIndex],0                  ; Yes => go to start of list
  192.  
  193. XindNotMax:
  194.     inc     [YIndex]                    ; Increase the Y index   
  195.     cmp     [YIndex],MaxNumbers         ; Have we reached the end of the list?
  196.     jb      StartCalc                   ; No => continue
  197.     mov     [YIndex],0                  ; Yes => go to start of list
  198.     
  199. NoEmptySpace:
  200.     popa                                ; Restore all registers
  201.     ret                                 ; Return to main program   
  202. CalcStar ENDP
  203.  
  204. ShowStars PROC NEAR
  205.     pusha                        ; Save all registers
  206.     mov     si,0                 ; si points to first record
  207. ShowLoop:
  208.     mov     cx,[Stars.Z+si]      ; Grab Z value of star
  209.     cmp     cx,0                 ; If Z = 0 then exit
  210.     je      ContinueStar         ; Do the next star
  211.  
  212.     mov     di,[Stars.Old+si]    ; Get old position of star
  213.     mov     byte ptr es:[di],0   ; Erase the old star
  214.  
  215.     mov     ax,[Stars.X+si]      ; Grab X value of star
  216.     mov     dx,256               ; Multiply X with 256
  217.     imul    dx
  218.     idiv    cx                   ; Divide by Z
  219.     add     ax,ScreenWidth/2     ; Add 160 to center it on the screen
  220.     mov     di,ax                ; di = X
  221.     cmp     di,ScreenWidth       ; Is the star in range ?
  222.     jae     TermStar             ; No => Do next star
  223.  
  224.     mov     ax,[Stars.Y+si]      ; Grab an Y value
  225.     mov     dx,256               ; Multiply Y with 256
  226.     imul    dx
  227.     idiv    cx                   ; Divide by Z (a bit slow but who carez)
  228.     add     ax,ScreenHeight/2    ; Add 100 to center it on the screen
  229.     cmp     ax,ScreenHeight      ; Is the star in range ?
  230.     jae     TermStar             ; No => Do next star
  231.     cmp     ax,90                ; Do not affect scroller
  232.     jl      InRange
  233.     cmp     ax,100               ; Text scrolls between 90 & 100
  234.     ja      InRange
  235.     jmp     TermStar             ; Star affects scroller so terminate it
  236. InRange:
  237.     imul    ax,ScreenWidth       ; ax = Y * ScreenWidth
  238.     add     di,ax                ; di = X + (Y * 320) 
  239.  
  240.     mov     [Stars.Old+si],di    ; Save the position
  241.  
  242.     add     ch,cs:[Stars.Col+si] ; Divide Z by 256 & add basecolor 0
  243.     mov     al,ch                ; Move color into al
  244.     add     al,5d                ; Add 5 to avoid fontcolors
  245.  
  246.     mov     byte ptr es:[di],al  ; Place the dot on the screen
  247.  
  248.     mov     ax,[WarpSpeed]
  249.     sub     cx,ax                ; Decrease Z with WarpSpeed
  250.     mov     [Stars.Z+si],cx      ; Save the new Z
  251.  
  252.     jmp     ContinueStar         ; Do the next star
  253.  
  254. TermStar:
  255.     mov     [Stars.Z+si],MinZ    ; Set Z to 0 => Star is terminated
  256.     dec     [NumActive]          ; Decrease number of active stars
  257.  
  258. ContinueStar:
  259.     add     si,StarStrucSize     ; si points to next record
  260.     cmp     si,StarStrucSize*MaxStars  ; Reached end of array ?
  261.     jb      ShowLoop             ; Continue with next star
  262.  
  263.     popa                         ; Restore all registers
  264.     ret                          ; Return to main program
  265. ShowStars ENDP
  266.  
  267.  
  268. ; === MAIN PROGRAM ===
  269.  
  270. START:
  271.  
  272.     cli                         ; Clear interrupt flag
  273.     call    SetVGA              ; Get in GFX-mode
  274.  
  275. ; === Set the palette ===
  276.     mov     ax,cs               ; Move CS into AX
  277.     mov     es,ax               ; es points to codesegment
  278.     mov     ax,1012h            ; Select write palette function
  279.     mov     bx,0                ; Start at color 0
  280.     mov     cx,23               ; Write 23 colors
  281.     mov     dx,offset Palette   ; es:dx points to palette data
  282.     int     10h                 ; Call VID interrupt & set palette
  283.     call    SavePalette         ; And save palette into array
  284.  
  285. ; === Initialize pointers ===
  286.     mov     ax,0a000h
  287.     mov     es,ax               ; es points to VGA
  288.     mov     ax,cs
  289.     mov     ds,ax               ; ds points to codesegment (data)
  290.  
  291. ; === Start scroll ===
  292. Reset:
  293.     lea     si,Text             ; si points to start of Text
  294. Mainthing:                      ; Main loop
  295.     lodsb                       ; Load a character in al    (si increased)
  296.     cmp     al,0                ; Have we reached the end of da text ?
  297.     je      Reset               ; Yep => Start over
  298.     push    si                  ; Save character-offset on stack
  299.     mov     bx,ax               ; Save the character into bx
  300.     mov     cx,0                ; Set character-counter for position in font
  301.     lea     si,Order            ; si points to offset Order
  302. Again:
  303.     lodsb                       ; Load the order-character (abcdef etc...)
  304.     cmp     ax,bx               ; Is it da same letter/character ?
  305.     je      Found               ; Yeah => Found it. . .
  306.     inc     cx                  ; Nope => Increase character-counter
  307.     jmp     Again               ; Compare with next character
  308. Found:
  309.     mov     ax,8                ; 7 pixels + black pixel = 8 pixels
  310.     mul     cx                  ; ax=ax*cx    (e.g:  E := 4 * 10;)
  311.  
  312.     mov     bx,4                ; Draw 4 * 2 vertical lines
  313. Hloop:
  314.     lea     si,Font             ; si points to start of Font
  315.     add     si,ax               ; si now points to character
  316.     mov     di,320*91           ; di points to startposition on VGA
  317.     mov     cx,9                ; Write 9 horizontal
  318. Vloop:
  319.     push    cx                  ; Save first loop-counter
  320.     mov     cx,2                ; Draw 2 new horizontal pixels
  321.     repz    movsb               ; And go !
  322.     add     di,318              ; Point to next location on VGA
  323.     add     si,318              ; Point to next source-location
  324.     pop     cx                  ; Restore loop-counter
  325.     loop    Vloop               ; Loop 9 times
  326. ; === Scroll the text and improve stars ===
  327.     push    ds ax               ; Save pointer to character + ds
  328.     mov     ax,0a000h           ; VGA-segment
  329.     mov     ds,ax               ; ds points to VGA
  330.     mov     si,320*90+2         ; Destination offset
  331.     mov     di,320*90           ; Source offset
  332.     mov     cx,10*320           ; Repeat factor => Number of bytes to copy
  333.     rep     movsb               ; And go ! (Hint: why not use words instead)
  334.  
  335.     mov     di,320*101          ; On some slow VGA-cards we have to plot
  336.     mov     cx,5                ; 5 black pixels just below the scroller
  337.     mov     al,0                ; on the left on the screen. Erase this
  338.     rep     stosb               ; code to see what I mean.
  339.  
  340.     call    WaitVrt             ; Wait for vertical retrace
  341.     call    CalcStar            ; Calculate new stars
  342.     call    ShowStars           ; Show all stars on VGA
  343.  
  344. ; === Want to quit ? ===
  345.     in      al,60h              ; Was ESCAPE pressed ?
  346.     cmp     al,1
  347.     je      QuitNow             ; If so, quit now. . .
  348.  
  349. ; === No quit ? then continue ===
  350.     pop     ax ds               ; Restore pointer to character + ds
  351.     add     ax,2                ; And add 2 to point to next 2 vertical lines
  352.     dec     bx                  ; Decrease line-counter
  353.     jnz     Hloop               ; If it's 0 then jump
  354.     pop     si                  ; Restore character-offset to do next char
  355.     jmp     Mainthing           ; And start over again
  356.  
  357. QuitNow:                        ; Quit everything
  358.     call    FadeOut             ; Fade da screen to black
  359.     call    SetText             ; Get in TXT-mode
  360.     mov     ax,cs
  361.     mov     ds,ax               ; ds points to codesegment (data)
  362.     lea     dx,Message          ; Load offset message
  363.     mov     ah,9                ; Select function 9 (print string)
  364.     int     21h                 ; Print the message
  365.     mov     ax,4c00h            ; Quit program
  366.     int     21h
  367.  
  368. END START                       ; End Of C<><>L Program !!!
  369.  
  370.  
  371.  
  372. ; Code by Vulture.
  373. ; Thanx to Draeden of VLA for example code.
  374. ; Don't be lame. Don't just rip the code.
  375. ; Give credit where it should be. I did.
  376. ; See ya in the next release.
  377.  
  378.